<template>
	<view>
		<view v-for="(item, index) in styleConfig" :key="index" @click="bindParent(item)">
			<component
				:is="item.name"
				:index="index"
				:activeName="activeName"
				:dataConfig="item"
				@changeBarg="changeBarg"
				@changeTab="changeTab"
				:tempArr="tempArr"
				:iSshowH="iSshowH"
				@detail="goDetail"
				@bindIframe="bindIframe"
			></component>
		</view>
    <!-- #ifdef MP -->
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse" :isGoIndex="false"></authorize>
     <!-- #endif -->
	</view>
</template>

<script>
import mConfig from './components/index.js';
import { getShare } from '@/api/public.js';
import { getTemlIds } from '@/api/api.js';
import { mapGetters } from 'vuex';
import { getDiy, getIndexData } from '@/api/api.js';
import { getGroomList } from '@/api/store.js';
import authorize from '@/components/Authorize.vue';
// import { goShopDetail } from '@/libs/order.js';
import { toLogin } from '@/libs/login.js';
export default {
	computed: mapGetters(['isLogin', 'uid']),
	components: {
    	authorize,
		...mConfig,
	},
	data() {
		return {
			styleConfig: [],
			tempArr: [],
			goodType: 3,
			loading: false,
			loadend: false,
			loadTitle: '下拉加载更多', //提示语
			page: 1,
      limit: this.$config.LIMIT,
      isAuto: true,
      isShowAuth: false, //是否隐藏授权
			iSshowH: false,
			numConfig: 0,
			isIframe: false,
			activeName: ''
		};
	},
	onLoad(options) {
		uni.getLocation({
			type: 'wgs84',
			success: function(res) {
				try {
					uni.setStorageSync('user_latitude', res.latitude);
					uni.setStorageSync('user_longitude', res.longitude);
				} catch {}
			}
		});
		this.diyData();
		this.getIndexData();
		// #ifdef H5
		this.setOpenShare();
		window.addEventListener('message', this.handleMessageFromParent, false);
		// #endif
	},
	mounted() {},
	methods: {
    onLoadFun() {
    },
    	// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
			},
		// #ifdef H5
		handleMessageFromParent(event) {
			var data = event.data;
		},
		// #endif
		// 对象转数组
		objToArr(data) {
			let obj = Object.keys(data);
      console.log('对象转数组:', obj);
			let m = obj.map(function(key) {
        data[key].name = key;
				return data[key];
			});
			return m;
		},
		diyData() {
			let that = this;
			getDiy().then(res => {
				try {
					if (res.data.a_headerSerch.hotList.list.length > 0) {
						uni.setStorageSync('hotList', res.data.a_headerSerch.hotList.list);
          }
        } catch (err) {}
        console.log('首页数据',res);
        that.styleConfig = that.objToArr(res.data);
			}).catch(err => {
        this.$util.Tips({title:err})
      });
    },
    bindParent(data) {
      if(data.name == 'b_swiperBg') {
        this.$util.Tips({title:'开发中，敬请期待哦！'})
      }; 
    },
		getIndexData() {
			let self = this;
			getIndexData().then(res => {
        console.log('热门',res);
				self.$store.commit('indexData/setIndexData', res.data);
			}).catch(err => {
        this.$util.Tips({title:err})
      });
		},
		// #ifdef H5
		// 微信分享；
		setOpenShare: function() {
			let that = this;
			if (that.$wechat.isWeixin()) {
				getShare().then(res => {
					let data = res.data.data;
					let configAppMessage = {
						desc: data.synopsis,
						title: data.title,
						link: location.href,
						imgUrl: data.img
					};
					that.$wechat.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData'], configAppMessage);
				});
			}
		}
		// #endif
	},
};
</script>

<style></style>
